package com.springboot.last_experiment.dao;

import com.springboot.last_experiment.entity.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AdminDao {
    @Select("select * from admin where admin_role=1")
    public List<Admin> getAllAdm();

    @Select(value = "select * from admin where admin_id=#{id} and admin_role=1")
    public Admin getAdmById(Integer id);

    @Select("select * from admin where " +
            " admin_role=1" +
            " and (admin_id=#{key} " +
            " or admin_name like '%${key}%'" +
            " or admin_sex=#{key})")
    public List<Admin> getAdmByKey(String key);

    @Delete("delete from admin where admin_id=#{id} and admin_role=1")
    public void deleteAdm(Integer id);

    @Options(useGeneratedKeys = true,keyProperty = "adminId")
    @Insert("insert into admin " +
            "(admin_name,admin_pass,admin_sex,admin_phone,admin_email,admin_role) " +
            "values (#{adminName},#{adminPass},#{adminSex},#{adminPhone},#{adminEmail},#{adminRole})")
    public void insertAdm(Admin admin);

    @Update("update admin set " +
            "admin_name=#{adminName}," +
            "admin_pass=#{adminPass}," +
            "admin_sex=#{adminSex}," +
            "admin_phone=#{adminPhone}," +
            "admin_email=#{adminEmail} where admin_id=#{adminId}")
    public void updateAdm(Admin admin);

    @Select(value = "select * from admin where admin_id=#{name} or admin_phone=#{name} or admin_email=#{name}")
    public Admin getByName(String name);
}
